package org.jetlinks.demo.protocol.siterwell.tcp.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

@AllArgsConstructor
@Getter
public enum MessageFixedHeader {

    COMMAND("57"),
    HEART("4d"),
    DAMAGE("00");

    private String fixedHeader;

    public static Optional<MessageFixedHeader> of(String header) {
        MessageFixedHeader[] headers = values();
        String lowerCaseHeader = header.toLowerCase();
        int len = headers.length;
        for (int i = 0; i < len; i++) {
            MessageFixedHeader curHeader = headers[i];
            if (curHeader.getFixedHeader().equals(lowerCaseHeader)) {
                return Optional.of(curHeader);
            }
        }
        return Optional.empty();
    }

}
